/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eval;

import java.io.File;
import java.io.FileInputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author
 */
public class Parse extends DefaultHandler {
    
    Script script;
    
    public Parse() {
        script = new Script();
    }
    
    public Script parseFile(File file) throws Exception {
        SAXParserFactory spf = SAXParserFactory.newInstance();
//    spf.setNamespaceAware(true);
        SAXParser saxParser = spf.newSAXParser();
        
        XMLReader xmlReader = saxParser.getXMLReader();
        xmlReader.setContentHandler(this);
        xmlReader.parse(new InputSource(new FileInputStream(file)));
        
        return script;
    }
    
    @Override
    public void startDocument() throws SAXException {
        System.out.println("Start document");
    }
    
    @Override
    public void endDocument() throws SAXException {
        System.out.println("End document");
    }
    
    @Override
    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
        System.out.println("Start element: " + qName);
    }
    
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        System.out.println("End element: " + qName);
    }
}
